﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SGQ.Controller;
using SGQ.Model;

namespace SGQ.View
{
    public partial class FormLogin : Form
    {
        public FormLogin()
        {
            InitializeComponent();
            user = new Usuario();
            user.Login = new Login();
            user.Departamento = new Departamento();
            controlLogin = new ControllerLogin();
            SessionApp = new SessionApplication();
        }

        private ControllerLogin controlLogin;
        private bool aprovado;
        private Usuario user;
        public Controller.SessionApplication SessionApp { get; set; }

        public bool isAprovado() {
            return aprovado;
        }

        public void pegaValores() {
            user.Login.Name = tbUser.Text;
            user.Login.Senha = tbPassword.Text;
        }
        public void limpaLabels() {
            tbUser.Text = null;
            tbPassword.Text = null;
        }

        private void btLogin_Click(object sender, EventArgs e)
        {
            realizarLogin();
        }

        private void realizarLogin()
        {
            try
            {
                pegaValores();
                user = controlLogin.ListDataSet(user);
                aprovado = true;
                limpaLabels();
                SessionApp.Usuario = user;
                this.Close();
            }
            catch (Exception e) {
                MessageCliente.MessageClient("Login Invalido ");
                aprovado = false;
                limpaLabels();
            }
        }

        private void FormLogin_Load(object sender, EventArgs e)
        {
            limpaLabels();
        }

        private void btClear_Click(object sender, EventArgs e)
        {
            limpaLabels();
        }

        private void label1_Click(object sender, EventArgs e)
        {
            aprovado = true;
            this.Close();
        }

    }
}
